package com.example.member.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.member.entity.Roles;
import com.example.member.entity.UserRoles;
import com.example.member.entity.Users;
import com.example.member.service.IRolesService;
import com.example.member.service.IUserRolesService;
import com.example.member.service.IUsersService;
import com.example.member.service.impl.UsersServiceImpl;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import utils.R;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李兰玉
 * @since 2023-11-12
 */
@RestController
@RequestMapping("/users")
public class UsersController {
    @Autowired
    private IUserRolesService iUserRolesService;
    @Autowired
    private IUsersService iUsersService;
    @Autowired
    private IRolesService iRolesService;
    @GetMapping("/getOne")
    public Map<String, Object> getOne(@RequestParam String username){
        Users user = iUsersService.getOne(new QueryWrapper<Users>().eq("username", username));
        UserRoles role = iUserRolesService.getOne(new QueryWrapper<UserRoles>().eq("user_id",user.getId()));
        Roles id = iRolesService.getOne(new QueryWrapper<Roles>().eq("id", role.getRoleId()));
        Map<String, Object> map = new HashMap<>();
        map.put("user",user.getPassword());
        map.put("role",id.getRoleName());
        return map;
    }

}
